/// <reference path="rsseasy.min.js" />
/// <reference path="jquery.min.js" />
/// <reference path="rsseasy.app.js" />
//充值
$('#chongzhi>article>button').click(function() {
	RssWin.MaskLayer.show();
	RssWin.LoadBox.show();
	RssEasy.WeiXin.onUnifiedOrder = function(json) {
		//		if(Url["kechengid"]) {
		//			location.href = "/fenxiang/kechengxiangqing.html?dataid=" + Url["kechengid"];
		//		}
		//		if(Url["peixunid"]){
		//			location.href = "/fenxiang/peixun.html?dataid=" + Url["peixunid"];
		//		}
		//支付成功
		RssEasy.WeiXin.onGetBrandWCPayRequest = function(data) {
			RssWin.MaskLayer.close();
			RssWin.LoadBox.close();
			if(Url["kechengid"]) {
				location.href = "/fenxiang/kechengxiangqing.html?dataid=" + Url["kechengid"];
			}
			if(Url["peixunid"]) {
				location.href = "/fenxiang/peixun.html?dataid=" + Url["peixunid"];
			}
			shuaxing();
			//充值成功弹窗

			$("#win").show();
		};
		//支付失败
		RssEasy.WeiXin.onGetBrandWCPayRequestFail = function() {
			RssWin.MaskLayer.close();
			RssWin.LoadBox.close();
			alert("支付失败或已取消");
			$('#expertDetails .pay_0').hide();
		};
		RssEasy.WeiXin.getBrandWCPayRequest(json);
	};
	//生成统一订单
	RssEasy.WeiXin.Recharge({
		"fee": $('#chongzhi>article>input').val()
	});
});
//8.88元提问
$('#expertDetails .pay_0 .pay_ a').click(function() {
	new Ajax('/order/buy').keyvalue({
		'target': 'zhuanjia',
		'zhuanjiaid': WenDaEntity.zhuanjiaid,
		"question": $("#question").val(),
		"tiwenfangshi": $("[data-position]").attr("data-position")
	}).getJson(function(data) {
		alert(dictdata.rsscode[data['rsscode']] || data['rsscode']);
	}, null, function() {
		RssWin.MaskLayer.close();
		$("#zhifu").hide();
	});
});
//购买课程
var realyue = $("#wode>article>.touxiang>h3");
var tanchuang = $("#paytansist>article>.yubuzu");
var quxiao = $("#paytansist>article>.yubuzu>p>b");
var qianwang = $("#paytansist>article>.yubuzu>p>a");
//余额
$('#quzhifu').click(function() {
	var wodeyue = "";
	new Ajax("/account/yue").keyvalue("myid", RssUser.Data.myid).getJson(function(data) {
		wodeyue = data[0].availablefunds;
		wodeyue = wodeyue * 1;
		var jia = $("#quzhifu").attr("jiage") * 1;
		var qid = $("#quzhifu").attr("quanid");
		if(jia <= wodeyue) {
			var kechengid = $("#quzhifu").attr("kechengid");
			var kecheng;
			var yunzhou;
			if(Url["kechengid"]) {
				kecheng = "kecheng";
				yunzhou="0";
			}
			if(Url["peixunid"]) {
				kecheng = "peixun";
				yunzhou=Url["week"];
			}
			new Ajax('/order/buy').keyvalue({
				'myid': RssUser.Data.myid,
				'kechengid': kechengid,
				'quanid': qid,
				'weeks':yunzhou,
				'target': kecheng
			}).getJson(function(data) {
				//			alert(dictdata.rsscode[data['rsscode']] || data['rsscode']);
				//			$("#kechengbuybtn").text("已购买");
			}, null, function() {
				$(".yyc").show();
				$("#ceshi").click(function() {
					if(Url["kechengid"]) {
						location.href = "/fenxiang/kechengxiangqing.html?dataid=" + Url["kechengid"];
						replaceHistory(); 
   window.addEventListener("popstate", function(e) { 
     window.location = 'http://news.ixinyun.cn/index.html';
   }, false); 
   function replaceHistory() { 
     var state = { 
       title: "title", 
       url: "http://news.ixinyun.cn/index.html"
     }; 
     window.history.replaceState(state, "title", "http://news.ixinyun.cn/index.html"); 
   }
					}
					if(Url["peixunid"]) {
						location.href = "/fenxiang/peixun.html?dataid=" + Url["peixunid"];
						replaceHistory(); 
   window.addEventListener("popstate", function(e) { 
     window.location = 'http://news.ixinyun.cn/index.html';
   }, false); 
   function replaceHistory() { 
     var state = { 
       title: "title", 
       url: "http://news.ixinyun.cn/index.html"
     }; 
     window.history.replaceState(state, "title", "http://news.ixinyun.cn/index.html"); 
   }
					}
				});
				new Ajax("/account/yue").keyvalue("myid", RssUser.Data.myid).getJson(function(data) {
					realyue.text(data[0].availablefunds);
				});
			});
		} else {
			tanchuang.show();
		};
	});
});

//点击取消
quxiao.click(function() {
	tanchuang.hide();
})
//点击我的钱包充值
$("#money").click(function() {
	$("#win").find("a").attr("href", "#wode");
});